//
//  Token.h
//  LightBasic
//
//  Created by Albert on 23/03/2011.
//  Copyright 2011 LightBasic Development Team. All rights reserved.
//
#pragma once
#include "TokenType.h"
#include "SourceLocation.h"

namespace lbc {
    
    /// string ref
    class StringRef;
    
    /**
     * This class represents a token that lexer produces
     */
    class Token : boost::noncopyable
    {
        public:
        
        /// create token from type only
        Token(TokenType type, unsigned int line, unsigned short column, unsigned short length);
        
        /// Create new token
        Token(TokenType type, const std::string & lexeme, unsigned int line, unsigned short column, unsigned short length);
        
        /// override default operator for pool allocation
        void * operator new(size_t);
        
        /// override default operator for pool deallocate
        void operator delete(void *);
        
        /// Get Token type
        inline TokenType GetType() const { return m_type; }
        
        /// Set token type
        inline void SetType(TokenType type) { m_type = type; }
        
        /// get token lexeme
        inline const StringRef & GetLexeme() const { return m_lexeme; }
        
        /// Get token location
        inline const SourceLocation & GetLocation() const { return m_location; }
        
        private:
        
        /// token type
        TokenType m_type;
        
        /// token location
        SourceLocation m_location;
        
        /// token lexeme string reference
        const StringRef & m_lexeme;
    };
    
}
